import subprocess
import sys
import os

sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
from PySVDAssistant import *

    
if __name__ == "__main__":

    
    file_name = r"./Test/xlsx"
    svdoutdir = r"-SVDOut=./Test"
    RTLoutdir = r"-RTLOut=./Test/RTLReg"
    paras = [
        'python', 'PySVDAssistant.py', file_name, svdoutdir,RTLoutdir,"-Debug"
    ]
    try:
        result = subprocess.run(paras, check=True, capture_output=True, text=True)
        print("输出结果:")
        print(result.stdout)  # 打印脚本的标准输出
        print(f"返回码={result.returncode}")
        
    except subprocess.CalledProcessError as e:
        result = None
        print(f"运行 PySVDAssistant.py 时发生错误: {e.stderr}")  # 打印错误信息

    if result != None and result.returncode == 0:        
        result = subprocess.run(["Test/SVDConv.exe",
                "Test/R2401.svd",
                "--generate=header",
                "--fields=struct",
                "--fields=enum",
                "--fields=macro",
                "--fields=struct-ansic",
                "--fields=macro",
                "-x INFO",
                "-o Test"
            ])
        print(result.stdout)  # 打印脚本的标准输出